export class Tile {
  x: number;
  y: number;
  value: number;
  previousPosition: any;
  mergedFrom: any = []; //记录合并的瓷砖，如果瓷砖 A 和瓷砖 B 合并成瓷砖 C，那么瓷砖 C 的 mergedFrom 属性将包含瓷砖 A 和瓷砖 B 的信息
  constructor(position: { x: number; y: number; }, value: number) {
    this.x = position.x;
    this.y = position.y;
    this.value = value || 2; // 默认初始化值 2

    this.previousPosition = null;
    this.mergedFrom = null;
  }

  savePosition() {
    this.previousPosition = { x: this.x, y: this.y };
  }

  updatePosition(position: { x: any; y: any; }) {
    this.x = position.x;
    this.y = position.y;
  }

  serialize() {
    // 序列化返回位置和值对象
    return {
      position: {
        x: this.x,
        y: this.y
      },
      value: this.value
    };
  }
}